﻿using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Configuration;

using PickGold.Security;
using PickGold.Database;
using PickGold.Entities.Table;

namespace PickGold.Util
{
    /// <summary>
    /// COnlineinfo 的摘要说明
    /// </summary>
    public class CUserOnline : CBaseUserOnline, IUserOnline
    {
        //
        protected IKernel _Kernel = null;
        protected DateTime _PageTime = DateTime.MinValue;
        //
        protected string _QueryKey = null;
        //
        private SUserOnline _ = null;
        //
        public CUserOnline(IKernel kernel) : base(kernel.Database)
        {
            this.setKernel(kernel);
        }
        //
        protected override void SetSchema()
        {
            this.SetSchema(new SUserOnline());
        }
        protected void SetSchema(SUserOnline s)
        {
            this._ = s;
            base.SetSchema(s);
        }
        //
		public void setKernel(IKernel value)
		{
			this._Kernel = value;
			if (value == null)
				base.Database = null;
			else
				base.Database = value.Database;
		}
        //
        public string BossName
        {
            get
            {
                if (this._.BossName == null)
                    this._.BossName = this._Kernel.Userinfo.GetName(this._.UserBoss);
                return this._.BossName;
            }
        }
        //
        public string SpaceName
        {
            get
            {
                if (this._.SpaceName == null)
                    this._.SpaceName = this._Kernel.Userinfo.GetName(this._.UserSpace);
                return this._.SpaceName;
            }
        }
        //
        public bool IsLogoned
        {
            set
            {
                if (this.ID < 0)
                    return;

                this.ItemFlags = CFlags.SetValue(this.ItemFlags, CFlags.LOGONED, value);
            }
            get
            {
                if (this.ID < 0)
                    return false;

                return CFlags.Test(this.ItemFlags, CFlags.LOGONED);
            }
        }
        //
        public DateTime PageTime
        {
            set
            {
                //需要用到它的上次数据，所以不能在一开始给它赋新值
                if (this._PageTime > value)
                    return;

                this._PageTime = value;
            }
            get
            {
                return this._PageTime;
            }
        }
        //
        public string QueryKey
        {
            get
            {
                if (this._QueryKey == null)
                    this._QueryKey = this._Kernel.Settings["key/online"];
                return this._QueryKey;
            }
        }
        //
    }
    //
    public class SUserOnline : SBaseUserOnline
    {
        //
        public string BossName = null;
        public string SpaceName = null;
        //
    }
    //
}
//
